package com.feng.chat.service.impl;

import cn.hutool.system.UserInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.feng.chat.common.Common;
import com.feng.chat.dto.KeepAlive;
import com.feng.chat.dto.RecordsDTO;
import com.feng.chat.dto.Result;
import com.feng.chat.entity.*;
import com.feng.chat.mapper.*;
import com.feng.chat.service.ITalkRecordsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feng.chat.service.IUsersService;
import com.feng.chat.utils.GetUserUtil;
import com.feng.chat.utils.JwtUtil;
import com.feng.chat.utils.MessageUtil;
import com.feng.chat.utils.RecordsUtil;
import com.feng.chat.vo.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.lang.reflect.Array;
import java.text.Collator;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户聊天记录表 服务实现类
 * </p>
 *
 * @author dyf
 * @since 2022-05-31
 */
@Service
public class TalkRecordsServiceImpl extends ServiceImpl<TalkRecordsMapper, TalkRecords> implements ITalkRecordsService {
    @Autowired
    private TalkRecordsMapper talkRecordsMapper;

    @Autowired
    private ContactMapper contactMapper;

    @Autowired
    private UsersMapper usersMapper;

    @Autowired
    private TalkRecordsDeleteMapper talkRecordsDeleteMapper;

    @Autowired
    private TalkRecordsFileMapper talkRecordsFileMapper;

    @Autowired
    private TalkRecordsCodeMapper codeMapper;
    @Autowired
    private TalkRecordsForwardMapper forwardMapper;
    @Autowired
    private TalkRecordsLocationMapper locationMapper;

    @Autowired
    private TalkRecordsInviteMapper talkRecordsInviteMapper;

    @Autowired
    private TalkRecordsVoteMapper talkRecordsVoteMapper;

    @Autowired
    private TalkRecordsVoteAnswerMapper talkRecordsVoteAnswerMapper;

    @Autowired
    private TalkRecordsLoginMapper talkRecordsLoginMapper;

    @Autowired
    private GroupMemberMapper groupMemberMapper;

    @Autowired
    private GroupNoticeMapper groupNoticeMapper;

    /**
     * 获取私信对话的信息列表
     *
     * @param talkType
     * @param uid
     * @param rid
     * @return
     */
    @Override
    public TalkRecords getLastMessage(Integer talkType, Integer uid, Integer rid) {
        TalkRecords messageList = talkRecordsMapper.getLastMessage(talkType, uid, rid);
        return messageList;
    }

    /**
     * 清除未读消息
     *
     * @param userId
     * @param receiver_id
     * @param talk_type
     * @return
     */
    @Override
    public Result unreadClear(Integer userId, Integer receiver_id, Integer talk_type) {
        if (talk_type==1){
            UpdateWrapper<TalkRecords> talkRecordsUpdateWrapper = new UpdateWrapper<>();
            talkRecordsUpdateWrapper.eq("user_id", receiver_id).eq("receiver_id", userId).eq("talk_type", talk_type).eq("is_revoke",0).set("is_read", 1);
            talkRecordsMapper.update(null,talkRecordsUpdateWrapper);
        }else {
            QueryWrapper<TalkRecords> talkRecordsQueryWrapper = new QueryWrapper<>();
            talkRecordsQueryWrapper.eq("receiver_id", receiver_id).eq("talk_type", talk_type).eq("is_revoke",0);
            List<TalkRecords> talkRecords = talkRecordsMapper.selectList(talkRecordsQueryWrapper);
            for (TalkRecords talkRecord : talkRecords) {
                if (talkRecord.getGroupRead()!=null){
                    List<String> read_ids = Arrays.asList(talkRecord.getGroupRead().split(","));
                    if (!read_ids.contains(userId.toString())){
                        String read = talkRecord.getGroupRead() + "," + userId;
                        talkRecord.setGroupRead(read);
                        talkRecordsMapper.updateById(talkRecord);
                    }
                }else {
                    talkRecord.setGroupRead(userId.toString());
                    talkRecordsMapper.updateById(talkRecord);
                }
            }
        }

        return Result.success();
    }

    /**
     * 获取聊天消息
     *
     * @param receiver_id
     * @param talk_type
     * @param limit
     * @param userId
     * @return
     */
    @Override
    public Result records(Integer receiver_id, Integer record_id, Integer talk_type, Integer limit, Integer userId) {
        List<TalkRecords> recordsList = null;
        if (talk_type == 1) {
            QueryWrapper<Contact> contactQueryWrapper = new QueryWrapper<>();
            contactQueryWrapper.eq("user_id",userId).eq("friend_id",receiver_id);
            Contact contact = contactMapper.selectOne(contactQueryWrapper);
            String deletedAt=null;
            if (contact.getStatus()==1){
                deletedAt=contact.getUpdatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER));
            }
            recordsList = talkRecordsMapper.getRecordsList(receiver_id, record_id, talk_type, limit, userId,deletedAt);
        } else {
            QueryWrapper<GroupMember> groupMemberQueryWrapper = new QueryWrapper<>();
            groupMemberQueryWrapper.eq("group_id",receiver_id).eq("user_id",userId);
            GroupMember groupMember = groupMemberMapper.selectOne(groupMemberQueryWrapper);

            String deletedAt=null;
            if (groupMember.getDeletedAt()!=null){
                deletedAt = groupMember.getDeletedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER));
            }
            recordsList = talkRecordsMapper.getGroupRecordsList(receiver_id, record_id, talk_type, limit, userId,deletedAt);
        }

        RecordsDTO recordsDTO = new RecordsDTO();
        recordsDTO.setLimit(limit);
        TalkRecords item = recordsList.get(recordsList.size() - 1);
        recordsDTO.setRecord_id(item.getId());

        List<RecordsRowsVO> recordsRowsVOS = new ArrayList<>();

        recordsRowsVOS = recordsList.stream().map(talkRecords -> {
            RecordsRowsVO recordsRowsVO = new RecordsRowsVO();
            recordsRowsVO.setId(talkRecords.getId());
            recordsRowsVO.setIs_mark(talkRecords.getIsMark());
            recordsRowsVO.setIs_read(talkRecords.getIsRead());
            recordsRowsVO.setIs_revoke(talkRecords.getIsRevoke());
            recordsRowsVO.setMsg_type(talkRecords.getMsgType());
            recordsRowsVO.setReceiver_id(talkRecords.getReceiverId());
            recordsRowsVO.setTalk_type(talkRecords.getTalkType());
            recordsRowsVO.setCreated_at(talkRecords.getUpdatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
            recordsRowsVO.setUser_id(talkRecords.getUserId());

            Users users = usersMapper.selectById(talkRecords.getUserId());
            if (users != null) {
                recordsRowsVO.setAvatar(users.getAvatar());
                recordsRowsVO.setNickname(users.getNickName());
            }
            switch (talkRecords.getMsgType()) {
                case 0:
                case 1:
                    recordsRowsVO.setContent(talkRecords.getContent());
                    break;
                case 2:
                    QueryWrapper<TalkRecordsFile> wrapper = new QueryWrapper<>();
                    wrapper.eq("record_id", talkRecords.getId());
                    TalkRecordsFile recordsType = talkRecordsFileMapper.selectOne(wrapper);

                    FileVO fileVO = new FileVO();
                    fileVO.setCreated_at(recordsType.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                    fileVO.setDrive(recordsType.getDrive());
                    fileVO.setId(recordsType.getId());
                    fileVO.setOriginal_name(recordsType.getOriginalName());
                    fileVO.setPath(recordsType.getPath());
                    fileVO.setRecord_id(recordsType.getRecordId());
                    fileVO.setSize(recordsType.getSize());
                    fileVO.setSource(recordsType.getSource());
                    fileVO.setSuffix(recordsType.getSuffix());
                    fileVO.setType(recordsType.getType());
                    fileVO.setUrl(recordsType.getUrl());
                    fileVO.setUser_id(recordsType.getUserId());

                    recordsRowsVO.setFile(fileVO);
                    break;
                case 3:
                    QueryWrapper<TalkRecordsForward> wrapperForward = new QueryWrapper<>();
                    wrapperForward.eq("record_id", talkRecords.getId());
                    TalkRecordsForward talkRecordsForward = forwardMapper.selectOne(wrapperForward);

                    ForwardVO forwardVO = new ForwardVO();
                    List<ForwardListVO> forwardListVOS = new ArrayList<>();
                    List<String> stringList = Arrays.asList(talkRecordsForward.getRecordsId().split(","));
                    for (String record : stringList) {
                        TalkRecords talkRecords2 = talkRecordsMapper.selectById(Integer.parseInt(record));
                        Users users1 = usersMapper.selectById(talkRecords2.getUserId());
                        ForwardListVO forwardListVO = new ForwardListVO(users1.getNickName(), MessageUtil.getMessageType(talkRecords2.getMsgType(), talkRecords2.getContent()));
                        forwardListVOS.add(forwardListVO);
                    }
                    forwardVO.setList(forwardListVOS);
                    forwardVO.setNum(forwardListVOS.size());

                    recordsRowsVO.setForward(forwardVO);
                    break;
                case 4:
                    QueryWrapper<TalkRecordsCode> wrapperCode = new QueryWrapper<>();
                    wrapperCode.eq("record_id", talkRecords.getId());
                    TalkRecordsCode talkRecordsCode = codeMapper.selectOne(wrapperCode);
                    CodeBlockVO codeBlockVO = new CodeBlockVO();
                    codeBlockVO.setCode(talkRecordsCode.getCode());
                    codeBlockVO.setRecord_id(talkRecords.getId());
                    codeBlockVO.setCreated_at(talkRecordsCode.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                    codeBlockVO.setId(talkRecordsCode.getId());
                    codeBlockVO.setLang(talkRecordsCode.getLang());
                    codeBlockVO.setUser_id(talkRecordsCode.getUserId());
                    recordsRowsVO.setCode_block(codeBlockVO);
                    break;
                case 5://投票消息
                    QueryWrapper<TalkRecordsVote> talkRecordsVoteQueryWrapper = new QueryWrapper<>();
                    talkRecordsVoteQueryWrapper.eq("record_id", talkRecords.getId());
                    TalkRecordsVote talkRecordsVote = talkRecordsVoteMapper.selectOne(talkRecordsVoteQueryWrapper);

                    VoteVO voteVO = new VoteVO();

                    DetailVO detailVO = new DetailVO();
                    detailVO.setAnswer_mode(talkRecordsVote.getAnswerMode());
                    detailVO.setAnswer_num(talkRecordsVote.getAnswerNum());
                    detailVO.setAnswered_num(talkRecordsVote.getAnsweredNum());
                    detailVO.setId(talkRecordsVote.getId());
                    detailVO.setRecord_id(talkRecordsVote.getRecordId());

                    long time = Date.from(talkRecordsVote.getCreatedAt().toInstant(ZoneOffset.of("+8"))).getTime();
                    if (time+ JwtUtil.expiresIn<System.currentTimeMillis()){
                        talkRecordsVote.setStatus(1);
                        talkRecordsVoteMapper.updateById(talkRecordsVote);
                    }
                    detailVO.setStatus(talkRecordsVote.getStatus());
                    detailVO.setTitle(talkRecordsVote.getTitle());

                    List<AnswerOptionVO> answerOptionVOS = new ArrayList<>();
                    String[] answerOptions = talkRecordsVote.getAnswerOption().split(",");
                    for (int i = 0; i < answerOptions.length; i++) {
                        AnswerOptionVO answerOptionVO = new AnswerOptionVO();

                        char key = (char) (65 + i);
                        answerOptionVO.setKey(String.valueOf(key));
                        answerOptionVO.setValue(answerOptions[i]);

                        answerOptionVOS.add(answerOptionVO);
                    }
                    detailVO.setAnswer_option(answerOptionVOS);
                    voteVO.setDetail(detailVO);

                    StatisticsVO statisticsVO = new StatisticsVO();
                    statisticsVO.setCount(talkRecordsVote.getAnsweredNum());
                    Map<String, Long> options = new HashMap<>();
                    for (int i = 0; i < answerOptions.length; i++) {
                        char key = (char) (65 + i);
                        QueryWrapper<TalkRecordsVoteAnswer> talkRecordsVoteAnswerQueryWrapper = new QueryWrapper<>();
                        talkRecordsVoteAnswerQueryWrapper.eq("vote_id", talkRecordsVote.getId()).eq("answer_option", String.valueOf(key));
                        Long count = talkRecordsVoteAnswerMapper.selectCount(talkRecordsVoteAnswerQueryWrapper);
                        options.put(String.valueOf(key), count);
                    }
                    statisticsVO.setOptions(options);
                    voteVO.setStatistics(statisticsVO);

                    List<Integer> voteUsers = new ArrayList<>();
                    QueryWrapper<TalkRecordsVoteAnswer> talkRecordsVoteAnswerQueryWrapper = new QueryWrapper<>();
                    talkRecordsVoteAnswerQueryWrapper.eq("vote_id", talkRecordsVote.getId());
                    List<TalkRecordsVoteAnswer> talkRecordsVoteAnswers = talkRecordsVoteAnswerMapper.selectList(talkRecordsVoteAnswerQueryWrapper);
                    voteUsers = talkRecordsVoteAnswers.stream().map(TalkRecordsVoteAnswer::getUserId).collect(Collectors.toList());
                    voteVO.setVote_users(voteUsers);
                    recordsRowsVO.setVote(voteVO);
                    break;
                case 6:
                    QueryWrapper<GroupNotice> groupNoticeQueryWrapper = new QueryWrapper<>();
                    groupNoticeQueryWrapper.eq("record_id", talkRecords.getId());
                    GroupNotice groupNotice = groupNoticeMapper.selectOne(groupNoticeQueryWrapper);
                    NoticeVO noticeVO = new NoticeVO();
                    noticeVO.setConfirm_users(groupNotice.getConfirmUsers());
                    noticeVO.setContent(groupNotice.getContent());
                    noticeVO.setCreated_at(groupNotice.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                    noticeVO.setCreator_id(groupNotice.getCreatorId());
                    noticeVO.setGroup_id(groupNotice.getGroupId());
                    noticeVO.setId(groupNotice.getId());
                    noticeVO.setIs_confirm(groupNotice.getIsConfirm());
                    noticeVO.setIs_delete(groupNotice.getIsDelete());
                    noticeVO.setIs_top(groupNotice.getIsTop());
                    noticeVO.setTitle(groupNotice.getTitle());
                    noticeVO.setUpdated_at(groupNotice.getUpdatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));

                    Users creatorUser = usersMapper.selectById(groupNotice.getCreatorId());
                    noticeVO.setAvatar(creatorUser.getAvatar());
                    noticeVO.setNickname(creatorUser.getNickName());
                    recordsRowsVO.setNotice(noticeVO);
                    break;
                case 8:
                    QueryWrapper<TalkRecordsLogin> talkRecordsLoginQueryWrapper = new QueryWrapper<>();
                    talkRecordsLoginQueryWrapper.eq("record_id", talkRecords.getId());
                    TalkRecordsLogin talkRecordsLogin = talkRecordsLoginMapper.selectOne(talkRecordsLoginQueryWrapper);

                    LoginVO loginVO = new LoginVO();
                    loginVO.setAddress(talkRecordsLogin.getAddress());
                    loginVO.setAgent(talkRecordsLogin.getAgent());
                    loginVO.setCreated_at(talkRecordsLogin.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                    loginVO.setIp(talkRecordsLogin.getIp());
                    loginVO.setPlatform(talkRecordsLogin.getPlatform());
                    loginVO.setReason(talkRecordsLogin.getReason());

                    recordsRowsVO.setLogin(loginVO);
                    break;
                case 9:
                    QueryWrapper<TalkRecordsInvite> talkRecordsInviteQueryWrapper = new QueryWrapper<>();
                    talkRecordsInviteQueryWrapper.eq("record_id", talkRecords.getId());
                    TalkRecordsInvite talkRecordsInvite = talkRecordsInviteMapper.selectOne(talkRecordsInviteQueryWrapper);

                    InviteVO inviteVO = new InviteVO();
                    inviteVO.setType(talkRecordsInvite.getType());//入群通知

                    UserVO operate_user = new UserVO();
                    Users user = usersMapper.selectById(talkRecordsInvite.getOperateUserId());
                    operate_user.setId(user.getId());
                    operate_user.setNickname(user.getNickName());
                    inviteVO.setOperate_user(operate_user);

                    String[] userIds = talkRecordsInvite.getUserIds().split(",");
                    List<String> userIdsList = Arrays.asList(userIds);
                    List<UserVO> userVOS = new ArrayList<>();
                    userVOS = userIdsList.stream().map(id -> {
                        Users users1 = usersMapper.selectById(id);
                        UserVO userVO = new UserVO();
                        userVO.setId(users1.getId());
                        userVO.setNickname(users1.getNickName());
                        return userVO;
                    }).collect(Collectors.toList());
                    inviteVO.setUsers(userVOS);
                    recordsRowsVO.setInvite(inviteVO);
                    break;
            }

            return recordsRowsVO;
        }).collect(Collectors.toList());

        recordsDTO.setRows(recordsRowsVOS);
        return Result.success(recordsDTO);
    }

    /**
     * 发送文本消息
     *
     * @param textVO
     * @param userId
     * @return
     */
    @Override
    public Result text(TextVO textVO, Integer userId) {
        TalkRecords talkRecords = new TalkRecords();
        talkRecords.setContent(textVO.getText());
        talkRecords.setUserId(userId);
        talkRecords.setReceiverId(textVO.getReceiver_id());
        talkRecords.setTalkType(textVO.getTalk_type());
        talkRecords.setMsgType(1);
        if (textVO.getTalk_type()==2){
            talkRecords.setGroupRead(userId.toString());
        }
        boolean save = save(talkRecords);

        KeepAlive keepAlive = new KeepAlive();
        keepAlive.setEvent(Common.EVENT_TALK);

        EventTalkVO eventTalkVO = new EventTalkVO();
        eventTalkVO.setReceiver_id(talkRecords.getReceiverId());
        eventTalkVO.setSender_id(talkRecords.getUserId());
        eventTalkVO.setTalk_type(talkRecords.getTalkType());

        EventTalkDataVO eventTalkDataVO = new EventTalkDataVO();
        eventTalkDataVO.setContent(talkRecords.getContent());
        eventTalkDataVO.setCreated_at(talkRecords.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
        eventTalkDataVO.setId(talkRecords.getId());
        eventTalkDataVO.setIs_mark(talkRecords.getIsMark());
        eventTalkDataVO.setIs_read(talkRecords.getIsRead());
        eventTalkDataVO.setIs_revoke(talkRecords.getIsRevoke());
        eventTalkDataVO.setMsg_type(talkRecords.getMsgType());
        eventTalkDataVO.setReceiver_id(talkRecords.getReceiverId());
        eventTalkDataVO.setTalk_type(talkRecords.getTalkType());
        eventTalkDataVO.setUser_id(talkRecords.getUserId());

        Users users = usersMapper.selectById(talkRecords.getUserId());
        eventTalkDataVO.setAvatar(users.getAvatar());


        eventTalkVO.setData(eventTalkDataVO);
        keepAlive.setContent(eventTalkVO);

        GetUserUtil.sendMessage(keepAlive, userId);
        if (textVO.getTalk_type() == 1) {
            if (GetUserUtil.isOnLine(textVO.getReceiver_id()) == 1) {
                GetUserUtil.sendMessage(keepAlive, textVO.getReceiver_id());
            }
        } else {
            List<Integer> groupMember = groupMemberMapper.getGroupMember(textVO.getReceiver_id());
            groupMember.remove(userId);
            for (Integer user_id : groupMember) {
                if (GetUserUtil.isOnLine(user_id) == 1) {
                    GetUserUtil.sendMessage(keepAlive, user_id);
                }
            }
        }


        return Result.success();
    }

    /**
     * 消息撤回
     *
     * @param record_id
     * @return
     */
    @Override
    public Result revoke(Integer record_id) {
        TalkRecords records = getById(record_id);
        long createdAt = records.getCreatedAt().toInstant(ZoneOffset.of("+8")).toEpochMilli();
        long current = System.currentTimeMillis();
        if (current - createdAt > Common.TWO_MINUTE) {
            return Result.fail("消息已超时，无法撤回");
        } else {
            records.setIsRevoke(1);
            boolean update = updateById(records);

            EventTalkRevokeVO eventTalkRevokeVO = new EventTalkRevokeVO(records.getReceiverId(), records.getId(), records.getUserId(), records.getTalkType());
            KeepAlive keepAlive = new KeepAlive();
            keepAlive.setEvent(Common.EVENT_TALK_REVOKE);
            keepAlive.setContent(eventTalkRevokeVO);

            GetUserUtil.sendMessage(keepAlive, eventTalkRevokeVO.getSender_id());
            if (GetUserUtil.isOnLine(eventTalkRevokeVO.getReceiver_id()) == 1) {
                GetUserUtil.sendMessage(keepAlive, eventTalkRevokeVO.getReceiver_id());
            }
            return Result.success();
        }
    }

    /**
     * 消息删除
     *
     * @param receiver_id
     * @param record_id
     * @param talk_type
     * @param userId
     * @return
     */
    @Override
    public Result delete(Integer receiver_id, Integer record_id, Integer talk_type, Integer userId) {
        TalkRecordsDelete talkRecordsDelete = new TalkRecordsDelete();
        talkRecordsDelete.setRecordId(record_id);
        talkRecordsDelete.setUserId(userId);
        talkRecordsDeleteMapper.insert(talkRecordsDelete);

        return Result.success();
    }

    /**
     * 消息转发
     *
     * @param messageForwardVO
     * @param userId
     * @return
     */
    @Override
    public Result forward(MessageForwardVO messageForwardVO, Integer userId) {
        //获取转发的消息id
        String records_ids = messageForwardVO.getRecords_ids();

        List<Integer> records = Arrays.stream(records_ids.split(",")).map(Integer::valueOf).collect(Collectors.toList());

        records.sort(Comparator.comparing(Integer::intValue));
        QueryWrapper<TalkRecords> talkRecordsQueryWrapper = new QueryWrapper<>();
        talkRecordsQueryWrapper.in("id", records).orderByAsc("id");
        List<TalkRecords> talkRecords = talkRecordsMapper.selectList(talkRecordsQueryWrapper);


        for (TalkRecords item : talkRecords) {
            if (item.getMsgType() == 5 || item.getMsgType() == 6 || item.getMsgType() == 8 || item.getMsgType() == 9) {
                return Result.fail(400, "转发消息异常");
            }
        }


        //获取接收者群id
        String receive_group_ids = messageForwardVO.getReceive_group_ids();
        List<Integer> receive_groups =null;
        if (receive_group_ids!=null&&!"".equals(receive_group_ids)) {
            receive_groups = Arrays.stream(receive_group_ids.split(",")).map(Integer::valueOf).collect(Collectors.toList());
        }
        //获取接收者好友id
        String receive_user_ids = messageForwardVO.getReceive_user_ids();
        List<Integer> receive_users=null;
        if (receive_user_ids!=null&&!"".equals(receive_user_ids)){
            receive_users = Arrays.stream(receive_user_ids.split(",")).map(Integer::valueOf).collect(Collectors.toList());
        }

        Users users = usersMapper.selectById(userId);

        if (messageForwardVO.getForward_mode() == 1) { //逐条转发
            /*for (TalkRecords talkRecord : talkRecords) {

                switch (talkRecord.getMsgType()) {
                    case 1:
                        for (Integer receive_user : receive_users) {
                            KeepAlive keepAlive = new KeepAlive();
                            keepAlive.setEvent(Common.EVENT_TALK);
                            TalkRecords talkRecords1 = new TalkRecords();
                            talkRecords1.setMsgType(1);
                            talkRecords1.setTalkType(1);
                            talkRecords1.setReceiverId(receive_user);
                            talkRecords1.setUserId(userId);
                            talkRecords1.setContent(talkRecord.getContent());

                            int insert = talkRecordsMapper.insert(talkRecords1);

                            EventTalkVO eventTalkVO = new EventTalkVO();
                            eventTalkVO.setTalk_type(1);
                            eventTalkVO.setSender_id(userId);
                            eventTalkVO.setReceiver_id(receive_user);

                            EventTalkDataVO eventTalkDataVO = new EventTalkDataVO();


                            eventTalkDataVO.setAvatar(users.getAvatar());
                            eventTalkDataVO.setUser_id(userId);
                            eventTalkDataVO.setTalk_type(1);
                            eventTalkDataVO.setReceiver_id(receive_user);
                            eventTalkDataVO.setNickname(users.getNickName());
                            eventTalkDataVO.setMsg_type(1);
                            eventTalkDataVO.setContent(talkRecords1.getContent());
                            eventTalkDataVO.setIs_revoke(talkRecords1.getIsRevoke());
                            eventTalkDataVO.setIs_read(talkRecords1.getIsRead());
                            eventTalkDataVO.setIs_mark(talkRecords1.getIsMark());
                            eventTalkDataVO.setId(talkRecords1.getId());
                            eventTalkDataVO.setCreated_at(talkRecords1.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                            eventTalkVO.setData(eventTalkDataVO);
                            keepAlive.setContent(eventTalkVO);

                            GetUserUtil.sendMessage(keepAlive, userId);
                            if (GetUserUtil.isOnLine(receive_user) == 1) {
                                GetUserUtil.sendMessage(keepAlive, receive_user);
                            }
                        }
                        break;
                    case 2:
                        for (Integer receive_user : receive_users) {
                            TalkRecords talkRecords1 = new TalkRecords();
                            talkRecords1.setMsgType(2);
                            talkRecords1.setTalkType(1);
                            talkRecords1.setReceiverId(receive_user);
                            talkRecords1.setUserId(userId);
                            int insert = talkRecordsMapper.insert(talkRecords1);

                            TalkRecordsFile recordsFile = (TalkRecordsFile) MessageUtil.getRecordsType(talkRecord);
                            TalkRecordsFile talkRecordsFile = new TalkRecordsFile();
                            BeanUtils.copyProperties(recordsFile, talkRecordsFile, "recordId", "createdAt");
                            talkRecordsFile.setRecordId(talkRecords1.getId());
                            int insert1 = talkRecordsFileMapper.insert(talkRecordsFile);

                            KeepAlive keepAlive = new KeepAlive();

                            keepAlive.setEvent(Common.EVENT_TALK);
                            EventTalkVO eventTalkVO = new EventTalkVO();
                            eventTalkVO.setSender_id(userId);
                            eventTalkVO.setReceiver_id(receive_user);

                            EventTalkDataVO eventTalkDataVO = new EventTalkDataVO();

                            eventTalkDataVO.setAvatar(users.getAvatar());
                            eventTalkDataVO.setCreated_at(talkRecords1.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                            eventTalkDataVO.setId(talkRecords1.getId());
                            eventTalkDataVO.setIs_mark(talkRecords1.getIsMark());
                            eventTalkDataVO.setIs_read(talkRecords1.getIsRead());
                            eventTalkDataVO.setIs_revoke(talkRecords1.getIsRevoke());
                            eventTalkDataVO.setMsg_type(2);
                            eventTalkDataVO.setNickname(users.getAvatar());
                            eventTalkDataVO.setReceiver_id(receive_user);
                            eventTalkDataVO.setTalk_type(1);
                            eventTalkDataVO.setUser_id(userId);

                            FileVO fileVO = new FileVO();
                            fileVO.setCreated_at(talkRecordsFile.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                            fileVO.setDrive(talkRecordsFile.getDrive());
                            fileVO.setId(talkRecordsFile.getId());
                            fileVO.setOriginal_name(talkRecordsFile.getOriginalName());
                            fileVO.setPath(talkRecordsFile.getPath());
                            fileVO.setRecord_id(talkRecordsFile.getRecordId());
                            fileVO.setSize(talkRecordsFile.getSize());
                            fileVO.setSource(talkRecordsFile.getSource());
                            fileVO.setSuffix(talkRecordsFile.getSuffix());
                            fileVO.setType(talkRecordsFile.getType());
                            fileVO.setUrl(talkRecordsFile.getUrl());
                            fileVO.setUser_id(talkRecordsFile.getUserId());

                            eventTalkDataVO.setFile(fileVO);
                            eventTalkVO.setData(eventTalkDataVO);
                            keepAlive.setContent(eventTalkVO);

                            GetUserUtil.sendMessage(keepAlive, userId);
                            if (GetUserUtil.isOnLine(receive_user) == 1) {
                                GetUserUtil.sendMessage(keepAlive, receive_user);
                            }

                        }
                        break;
                    case 3:
                        for (Integer receive_user : receive_users) {
                            TalkRecords talkRecords1 = new TalkRecords();
                            talkRecords1.setMsgType(3);
                            talkRecords1.setTalkType(1);
                            talkRecords1.setReceiverId(receive_user);
                            talkRecords1.setUserId(userId);
                            int insert = talkRecordsMapper.insert(talkRecords1);

                            TalkRecordsForward recordsForward = (TalkRecordsForward) MessageUtil.getRecordsType(talkRecord);
                            TalkRecordsForward talkRecordsForward = new TalkRecordsForward();
                            BeanUtils.copyProperties(recordsForward, talkRecordsForward, "recordId", "createdAt");
                            talkRecordsForward.setRecordId(talkRecords1.getId());
                            int insert1 = forwardMapper.insert(talkRecordsForward);

                            KeepAlive keepAlive = new KeepAlive();

                            keepAlive.setEvent(Common.EVENT_TALK);
                            EventTalkVO eventTalkVO = new EventTalkVO();
                            eventTalkVO.setSender_id(userId);
                            eventTalkVO.setReceiver_id(receive_user);

                            EventTalkDataVO eventTalkDataVO = new EventTalkDataVO();

                            eventTalkDataVO.setAvatar(users.getAvatar());
                            eventTalkDataVO.setCreated_at(talkRecords1.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                            eventTalkDataVO.setId(talkRecords1.getId());
                            eventTalkDataVO.setIs_mark(talkRecords1.getIsMark());
                            eventTalkDataVO.setIs_read(talkRecords1.getIsRead());
                            eventTalkDataVO.setIs_revoke(talkRecords1.getIsRevoke());
                            eventTalkDataVO.setMsg_type(3);
                            eventTalkDataVO.setNickname(users.getAvatar());
                            eventTalkDataVO.setReceiver_id(receive_user);
                            eventTalkDataVO.setTalk_type(1);
                            eventTalkDataVO.setUser_id(userId);

                            ForwardVO forwardVO = new ForwardVO();
                            List<ForwardListVO> forwardListVOS = new ArrayList<>();
                            List<String> recordsList = Arrays.asList(talkRecordsForward.getRecordsId().split(","));
                            for (String record : recordsList) {
                                TalkRecords talkRecords2 = talkRecordsMapper.selectById(Integer.parseInt(record));
                                Users users1 = usersMapper.selectById(talkRecords2.getUserId());
                                ForwardListVO forwardListVO = new ForwardListVO(users1.getNickName(), MessageUtil.getMessageType(talkRecords2.getMsgType(), talkRecords2.getContent()));
                                forwardListVOS.add(forwardListVO);
                            }
                            forwardVO.setList(forwardListVOS);
                            forwardVO.setNum(forwardListVOS.size());


                            eventTalkDataVO.setForward(forwardVO);
                            eventTalkVO.setData(eventTalkDataVO);
                            keepAlive.setContent(eventTalkVO);

                            GetUserUtil.sendMessage(keepAlive, userId);
                            if (GetUserUtil.isOnLine(receive_user) == 1) {
                                GetUserUtil.sendMessage(keepAlive, receive_user);
                            }
                        }
                        break;
                    case 4:
                        for (Integer receive_user : receive_users) {
                            TalkRecords talkRecords1 = new TalkRecords();
                            talkRecords1.setMsgType(3);
                            talkRecords1.setTalkType(1);
                            talkRecords1.setReceiverId(receive_user);
                            talkRecords1.setUserId(userId);
                            int insert = talkRecordsMapper.insert(talkRecords1);

                            TalkRecordsCode recordsType = (TalkRecordsCode) MessageUtil.getRecordsType(talkRecord);
                            TalkRecordsCode talkRecordsCode = new TalkRecordsCode();
                            BeanUtils.copyProperties(recordsType, talkRecordsCode, "recordId", "createdAt");
                            talkRecordsCode.setRecordId(talkRecords1.getId());
                            int insert1 = codeMapper.insert(talkRecordsCode);

                            KeepAlive keepAlive = new KeepAlive();

                            keepAlive.setEvent(Common.EVENT_TALK);
                            EventTalkVO eventTalkVO = new EventTalkVO();
                            eventTalkVO.setSender_id(userId);
                            eventTalkVO.setReceiver_id(receive_user);

                            EventTalkDataVO eventTalkDataVO = new EventTalkDataVO();

                            eventTalkDataVO.setAvatar(users.getAvatar());
                            eventTalkDataVO.setCreated_at(talkRecords1.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                            eventTalkDataVO.setId(talkRecords1.getId());
                            eventTalkDataVO.setIs_mark(talkRecords1.getIsMark());
                            eventTalkDataVO.setIs_read(talkRecords1.getIsRead());
                            eventTalkDataVO.setIs_revoke(talkRecords1.getIsRevoke());
                            eventTalkDataVO.setMsg_type(4);
                            eventTalkDataVO.setNickname(users.getAvatar());
                            eventTalkDataVO.setReceiver_id(receive_user);
                            eventTalkDataVO.setTalk_type(1);
                            eventTalkDataVO.setUser_id(userId);

                            CodeBlockVO codeBlockVO = new CodeBlockVO();
                            codeBlockVO.setCode(talkRecordsCode.getCode());
                            codeBlockVO.setRecord_id(talkRecords1.getId());
                            codeBlockVO.setCreated_at(talkRecordsCode.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                            codeBlockVO.setId(talkRecordsCode.getId());
                            codeBlockVO.setLang(talkRecordsCode.getLang());
                            codeBlockVO.setUser_id(talkRecordsCode.getUserId());


                            eventTalkDataVO.setCode_block(codeBlockVO);
                            eventTalkVO.setData(eventTalkDataVO);
                            keepAlive.setContent(eventTalkVO);

                            GetUserUtil.sendMessage(keepAlive, userId);
                            if (GetUserUtil.isOnLine(receive_user) == 1) {
                                GetUserUtil.sendMessage(keepAlive, receive_user);
                            }
                        }
                        break;
                }
            }*/
            //转发给好友
            if (receive_users != null&&receive_users.size()>0){
                singleForward(receive_users,talkRecords,users,1,userId);
            }

            //转发群
            if (receive_groups!=null&&receive_groups.size()>0){
                singleForward(receive_groups,talkRecords,users,2,userId);
            }

        } else { //合并转发
            /*for (Integer receive_user : receive_users) {
                TalkRecords talkRecords1 = new TalkRecords();
                talkRecords1.setUserId(userId);
                talkRecords1.setTalkType(1);
                talkRecords1.setReceiverId(receive_user);
                talkRecords1.setMsgType(3);
                int insert = talkRecordsMapper.insert(talkRecords1);

                TalkRecordsForward talkRecordsForward = new TalkRecordsForward();
                talkRecordsForward.setRecordId(talkRecords1.getId());
                records.sort(Comparator.comparing(Integer::intValue));

                Arrays.stream(records_ids.split(",")).map(Integer::valueOf).collect(Collectors.toList());
                List<String> collect = records.stream().map(String::valueOf).collect(Collectors.toList());
                String join = String.join(",", collect);
                talkRecordsForward.setRecordsId(join);
                int insert1 = forwardMapper.insert(talkRecordsForward);

                KeepAlive keepAlive = new KeepAlive();
                keepAlive.setEvent(Common.EVENT_TALK);

                EventTalkVO eventTalkVO = new EventTalkVO();
                eventTalkVO.setReceiver_id(receive_user);
                eventTalkVO.setSender_id(userId);
                eventTalkVO.setTalk_type(1);

                EventTalkDataVO eventTalkDataVO = new EventTalkDataVO();

                eventTalkDataVO.setAvatar(users.getAvatar());
                eventTalkDataVO.setCreated_at(talkRecords1.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                eventTalkDataVO.setId(talkRecords1.getId());
                eventTalkDataVO.setIs_mark(talkRecords1.getIsMark());
                eventTalkDataVO.setIs_read(talkRecords1.getIsRead());
                eventTalkDataVO.setIs_revoke(talkRecords1.getIsRevoke());
                eventTalkDataVO.setMsg_type(3);
                eventTalkDataVO.setNickname(users.getAvatar());
                eventTalkDataVO.setReceiver_id(receive_user);
                eventTalkDataVO.setTalk_type(1);
                eventTalkDataVO.setUser_id(userId);

                ForwardVO forwardVO = new ForwardVO();
                ArrayList<ForwardListVO> forwardListVOS = new ArrayList<>();
                for (TalkRecords talkRecord : talkRecords) {
                    ForwardListVO forwardListVO = new ForwardListVO();
                    Users users1 = usersMapper.selectById(talkRecord.getUserId());
                    forwardListVO.setNickname(users1.getNickName());
                    forwardListVO.setText(MessageUtil.getMessageType(talkRecord.getMsgType(), talkRecord.getContent()));
                    forwardListVOS.add(forwardListVO);
                }
                forwardVO.setList(forwardListVOS);
                forwardVO.setNum(forwardListVOS.size());

                eventTalkDataVO.setForward(forwardVO);
                eventTalkVO.setData(eventTalkDataVO);
                keepAlive.setContent(eventTalkVO);

                GetUserUtil.sendMessage(keepAlive, userId);
                if (GetUserUtil.isOnLine(receive_user) == 1) {
                    GetUserUtil.sendMessage(keepAlive, receive_user);
                }
            }*/

            //转发给好友
            if (receive_users != null&&receive_users.size()>0){
                mergeForward(receive_users,records,talkRecords,users,1,userId);
            }

            //转发群
            if (receive_groups!=null&&receive_groups.size()>0){
                mergeForward(receive_groups,records,talkRecords,users,2,userId);
            }
        }
        return Result.success();
    }

    /**
     * 单条转发
     * @param user_ids
     * @param talkRecords
     * @param users
     * @param talk_type
     * @param userId
     */
    public void singleForward(List<Integer> user_ids,List<TalkRecords> talkRecords,Users users,Integer talk_type,Integer userId){
        for (TalkRecords talkRecord : talkRecords) {

            switch (talkRecord.getMsgType()) {
                case 1:
                    for (Integer receive_user : user_ids) {
                        KeepAlive keepAlive = new KeepAlive();
                        keepAlive.setEvent(Common.EVENT_TALK);
                        TalkRecords talkRecords1 = new TalkRecords();
                        talkRecords1.setMsgType(1);
                        talkRecords1.setTalkType(talk_type);
                        talkRecords1.setReceiverId(receive_user);
                        talkRecords1.setUserId(userId);
                        talkRecords1.setContent(talkRecord.getContent());

                        int insert = talkRecordsMapper.insert(talkRecords1);

                        EventTalkVO eventTalkVO = new EventTalkVO();
                        eventTalkVO.setTalk_type(talk_type);
                        eventTalkVO.setSender_id(userId);
                        eventTalkVO.setReceiver_id(receive_user);

                        EventTalkDataVO eventTalkDataVO = new EventTalkDataVO();


                        eventTalkDataVO.setAvatar(users.getAvatar());
                        eventTalkDataVO.setUser_id(userId);
                        eventTalkDataVO.setTalk_type(talk_type);
                        eventTalkDataVO.setReceiver_id(receive_user);
                        eventTalkDataVO.setNickname(users.getNickName());
                        eventTalkDataVO.setMsg_type(1);
                        eventTalkDataVO.setContent(talkRecords1.getContent());
                        eventTalkDataVO.setIs_revoke(talkRecords1.getIsRevoke());
                        eventTalkDataVO.setIs_read(talkRecords1.getIsRead());
                        eventTalkDataVO.setIs_mark(talkRecords1.getIsMark());
                        eventTalkDataVO.setId(talkRecords1.getId());
                        eventTalkDataVO.setCreated_at(talkRecords1.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                        eventTalkVO.setData(eventTalkDataVO);
                        keepAlive.setContent(eventTalkVO);

                        GetUserUtil.sendMessage(keepAlive, userId);
                        if (talk_type == 1) {
                            if (GetUserUtil.isOnLine(receive_user) == 1) {
                                GetUserUtil.sendMessage(keepAlive, receive_user);
                            }
                        } else {
                            List<Integer> groupMember = groupMemberMapper.getGroupMember(receive_user);
                            groupMember.remove(userId);
                            for (Integer user_id : groupMember) {
                                if (GetUserUtil.isOnLine(user_id) == 1) {
                                    GetUserUtil.sendMessage(keepAlive, user_id);
                                }
                            }
                        }
                    }
                    break;
                case 2:
                    for (Integer receive_user : user_ids) {
                        TalkRecords talkRecords1 = new TalkRecords();
                        talkRecords1.setMsgType(2);
                        talkRecords1.setTalkType(talk_type);
                        talkRecords1.setReceiverId(receive_user);
                        talkRecords1.setUserId(userId);
                        int insert = talkRecordsMapper.insert(talkRecords1);

                        QueryWrapper<TalkRecordsFile> wrapper = new QueryWrapper<>();
                        wrapper.eq("record_id", talkRecord.getId());
                        TalkRecordsFile recordsFile=talkRecordsFileMapper.selectOne(wrapper);
//                        TalkRecordsFile recordsFile = (TalkRecordsFile) MessageUtil.getRecordsType(talkRecord);
                        TalkRecordsFile talkRecordsFile = new TalkRecordsFile();
                        BeanUtils.copyProperties(recordsFile, talkRecordsFile, "id","recordId", "createdAt");
                        talkRecordsFile.setRecordId(talkRecords1.getId());
                        int insert1 = talkRecordsFileMapper.insert(talkRecordsFile);

                        KeepAlive keepAlive = new KeepAlive();

                        keepAlive.setEvent(Common.EVENT_TALK);
                        EventTalkVO eventTalkVO = new EventTalkVO();
                        eventTalkVO.setSender_id(userId);
                        eventTalkVO.setReceiver_id(receive_user);
                        eventTalkVO.setTalk_type(talk_type);

                        EventTalkDataVO eventTalkDataVO = new EventTalkDataVO();

                        eventTalkDataVO.setAvatar(users.getAvatar());
                        eventTalkDataVO.setCreated_at(talkRecords1.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                        eventTalkDataVO.setId(talkRecords1.getId());
                        eventTalkDataVO.setIs_mark(talkRecords1.getIsMark());
                        eventTalkDataVO.setIs_read(talkRecords1.getIsRead());
                        eventTalkDataVO.setIs_revoke(talkRecords1.getIsRevoke());
                        eventTalkDataVO.setMsg_type(2);
                        eventTalkDataVO.setNickname(users.getAvatar());
                        eventTalkDataVO.setReceiver_id(receive_user);
                        eventTalkDataVO.setTalk_type(talk_type);
                        eventTalkDataVO.setUser_id(userId);

                        FileVO fileVO = new FileVO();
                        fileVO.setCreated_at(talkRecordsFile.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                        fileVO.setDrive(talkRecordsFile.getDrive());
                        fileVO.setId(talkRecordsFile.getId());
                        fileVO.setOriginal_name(talkRecordsFile.getOriginalName());
                        fileVO.setPath(talkRecordsFile.getPath());
                        fileVO.setRecord_id(talkRecordsFile.getRecordId());
                        fileVO.setSize(talkRecordsFile.getSize());
                        fileVO.setSource(talkRecordsFile.getSource());
                        fileVO.setSuffix(talkRecordsFile.getSuffix());
                        fileVO.setType(talkRecordsFile.getType());
                        fileVO.setUrl(talkRecordsFile.getUrl());
                        fileVO.setUser_id(talkRecordsFile.getUserId());

                        eventTalkDataVO.setFile(fileVO);
                        eventTalkVO.setData(eventTalkDataVO);
                        keepAlive.setContent(eventTalkVO);

                        GetUserUtil.sendMessage(keepAlive, userId);
                        if (talk_type == 1) {
                            if (GetUserUtil.isOnLine(receive_user) == 1) {
                                GetUserUtil.sendMessage(keepAlive, receive_user);
                            }
                        } else {
                            List<Integer> groupMember = groupMemberMapper.getGroupMember(receive_user);
                            groupMember.remove(userId);
                            for (Integer user_id : groupMember) {
                                if (GetUserUtil.isOnLine(user_id) == 1) {
                                    GetUserUtil.sendMessage(keepAlive, user_id);
                                }
                            }
                        }
                    }
                    break;
                case 3:
                    for (Integer receive_user : user_ids) {
                        TalkRecords talkRecords1 = new TalkRecords();
                        talkRecords1.setMsgType(3);
                        talkRecords1.setTalkType(talk_type);
                        talkRecords1.setReceiverId(receive_user);
                        talkRecords1.setUserId(userId);
                        int insert = talkRecordsMapper.insert(talkRecords1);

                        QueryWrapper<TalkRecordsForward> wrapperForward = new QueryWrapper<>();
                        wrapperForward.eq("record_id", talkRecord.getId());
                        TalkRecordsForward recordsForward=forwardMapper.selectOne(wrapperForward);
//                        TalkRecordsForward recordsForward = (TalkRecordsForward) MessageUtil.getRecordsType(talkRecord);
                        TalkRecordsForward talkRecordsForward = new TalkRecordsForward();
                        BeanUtils.copyProperties(recordsForward, talkRecordsForward, "id","recordId", "createdAt");
                        talkRecordsForward.setRecordId(talkRecords1.getId());
                        int insert1 = forwardMapper.insert(talkRecordsForward);

                        KeepAlive keepAlive = new KeepAlive();

                        keepAlive.setEvent(Common.EVENT_TALK);
                        EventTalkVO eventTalkVO = new EventTalkVO();
                        eventTalkVO.setSender_id(userId);
                        eventTalkVO.setReceiver_id(receive_user);
                        eventTalkVO.setTalk_type(talk_type);

                        EventTalkDataVO eventTalkDataVO = new EventTalkDataVO();

                        eventTalkDataVO.setAvatar(users.getAvatar());
                        eventTalkDataVO.setCreated_at(talkRecords1.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                        eventTalkDataVO.setId(talkRecords1.getId());
                        eventTalkDataVO.setIs_mark(talkRecords1.getIsMark());
                        eventTalkDataVO.setIs_read(talkRecords1.getIsRead());
                        eventTalkDataVO.setIs_revoke(talkRecords1.getIsRevoke());
                        eventTalkDataVO.setMsg_type(3);
                        eventTalkDataVO.setNickname(users.getAvatar());
                        eventTalkDataVO.setReceiver_id(receive_user);
                        eventTalkDataVO.setTalk_type(talk_type);
                        eventTalkDataVO.setUser_id(userId);

                        ForwardVO forwardVO = new ForwardVO();
                        List<ForwardListVO> forwardListVOS = new ArrayList<>();
                        List<String> recordsList = Arrays.asList(talkRecordsForward.getRecordsId().split(","));
                        for (String record : recordsList) {
                            TalkRecords talkRecords2 = talkRecordsMapper.selectById(Integer.parseInt(record));
                            Users users1 = usersMapper.selectById(talkRecords2.getUserId());
                            ForwardListVO forwardListVO = new ForwardListVO(users1.getNickName(), MessageUtil.getMessageType(talkRecords2.getMsgType(), talkRecords2.getContent()));
                            forwardListVOS.add(forwardListVO);
                        }
                        forwardVO.setList(forwardListVOS);
                        forwardVO.setNum(forwardListVOS.size());


                        eventTalkDataVO.setForward(forwardVO);
                        eventTalkVO.setData(eventTalkDataVO);
                        keepAlive.setContent(eventTalkVO);

                        GetUserUtil.sendMessage(keepAlive, userId);
                        if (talk_type == 1) {
                            if (GetUserUtil.isOnLine(receive_user) == 1) {
                                GetUserUtil.sendMessage(keepAlive, receive_user);
                            }
                        } else {
                            List<Integer> groupMember = groupMemberMapper.getGroupMember(receive_user);
                            groupMember.remove(userId);
                            for (Integer user_id : groupMember) {
                                if (GetUserUtil.isOnLine(user_id) == 1) {
                                    GetUserUtil.sendMessage(keepAlive, user_id);
                                }
                            }
                        }
                    }
                    break;
                case 4:
                    for (Integer receive_user : user_ids) {
                        TalkRecords talkRecords1 = new TalkRecords();
                        talkRecords1.setMsgType(3);
                        talkRecords1.setTalkType(talk_type);
                        talkRecords1.setReceiverId(receive_user);
                        talkRecords1.setUserId(userId);
                        int insert = talkRecordsMapper.insert(talkRecords1);

                        QueryWrapper<TalkRecordsCode> wrapperCode = new QueryWrapper<>();
                        wrapperCode.eq("record_id", talkRecord.getId());
                        TalkRecordsCode recordsType=codeMapper.selectOne(wrapperCode);
//                        TalkRecordsCode recordsType = (TalkRecordsCode) MessageUtil.getRecordsType(talkRecord);
                        TalkRecordsCode talkRecordsCode = new TalkRecordsCode();
                        BeanUtils.copyProperties(recordsType, talkRecordsCode, "id","recordId", "createdAt");
                        talkRecordsCode.setRecordId(talkRecords1.getId());
                        int insert1 = codeMapper.insert(talkRecordsCode);

                        KeepAlive keepAlive = new KeepAlive();

                        keepAlive.setEvent(Common.EVENT_TALK);
                        EventTalkVO eventTalkVO = new EventTalkVO();
                        eventTalkVO.setSender_id(userId);
                        eventTalkVO.setReceiver_id(receive_user);
                        eventTalkVO.setTalk_type(talk_type);

                        EventTalkDataVO eventTalkDataVO = new EventTalkDataVO();

                        eventTalkDataVO.setAvatar(users.getAvatar());
                        eventTalkDataVO.setCreated_at(talkRecords1.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                        eventTalkDataVO.setId(talkRecords1.getId());
                        eventTalkDataVO.setIs_mark(talkRecords1.getIsMark());
                        eventTalkDataVO.setIs_read(talkRecords1.getIsRead());
                        eventTalkDataVO.setIs_revoke(talkRecords1.getIsRevoke());
                        eventTalkDataVO.setMsg_type(4);
                        eventTalkDataVO.setNickname(users.getAvatar());
                        eventTalkDataVO.setReceiver_id(receive_user);
                        eventTalkDataVO.setTalk_type(talk_type);
                        eventTalkDataVO.setUser_id(userId);

                        CodeBlockVO codeBlockVO = new CodeBlockVO();
                        codeBlockVO.setCode(talkRecordsCode.getCode());
                        codeBlockVO.setRecord_id(talkRecords1.getId());
                        codeBlockVO.setCreated_at(talkRecordsCode.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                        codeBlockVO.setId(talkRecordsCode.getId());
                        codeBlockVO.setLang(talkRecordsCode.getLang());
                        codeBlockVO.setUser_id(talkRecordsCode.getUserId());


                        eventTalkDataVO.setCode_block(codeBlockVO);
                        eventTalkVO.setData(eventTalkDataVO);
                        keepAlive.setContent(eventTalkVO);

                        GetUserUtil.sendMessage(keepAlive, userId);
                        if (talk_type == 1) {
                            if (GetUserUtil.isOnLine(receive_user) == 1) {
                                GetUserUtil.sendMessage(keepAlive, receive_user);
                            }
                        } else {
                            List<Integer> groupMember = groupMemberMapper.getGroupMember(receive_user);
                            groupMember.remove(userId);
                            for (Integer user_id : groupMember) {
                                if (GetUserUtil.isOnLine(user_id) == 1) {
                                    GetUserUtil.sendMessage(keepAlive, user_id);
                                }
                            }
                        }
                    }
                    break;
            }
        }
    }

    /**
     * 合并转发
     * @param user_ids
     * @param records
     * @param talkRecords
     * @param users
     * @param talk_type
     * @param userId
     */
    public void mergeForward(List<Integer> user_ids,List<Integer> records,List<TalkRecords> talkRecords,Users users,Integer talk_type,Integer userId){
        for (Integer receive_user : user_ids) {
            TalkRecords talkRecords1 = new TalkRecords();
            talkRecords1.setUserId(userId);
            talkRecords1.setTalkType(talk_type);
            talkRecords1.setReceiverId(receive_user);
            talkRecords1.setMsgType(3);
            int insert = talkRecordsMapper.insert(talkRecords1);

            TalkRecordsForward talkRecordsForward = new TalkRecordsForward();
            talkRecordsForward.setRecordId(talkRecords1.getId());
            records.sort(Comparator.comparing(Integer::intValue));

//            Arrays.stream(records_ids.split(",")).map(Integer::valueOf).collect(Collectors.toList());
            List<String> collect = records.stream().map(String::valueOf).collect(Collectors.toList());
            String join = String.join(",", collect);
            talkRecordsForward.setRecordsId(join);
            int insert1 = forwardMapper.insert(talkRecordsForward);

            KeepAlive keepAlive = new KeepAlive();
            keepAlive.setEvent(Common.EVENT_TALK);

            EventTalkVO eventTalkVO = new EventTalkVO();
            eventTalkVO.setReceiver_id(receive_user);
            eventTalkVO.setSender_id(userId);
            eventTalkVO.setTalk_type(talk_type);

            EventTalkDataVO eventTalkDataVO = new EventTalkDataVO();

            eventTalkDataVO.setAvatar(users.getAvatar());
            eventTalkDataVO.setCreated_at(talkRecords1.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
            eventTalkDataVO.setId(talkRecords1.getId());
            eventTalkDataVO.setIs_mark(talkRecords1.getIsMark());
            eventTalkDataVO.setIs_read(talkRecords1.getIsRead());
            eventTalkDataVO.setIs_revoke(talkRecords1.getIsRevoke());
            eventTalkDataVO.setMsg_type(3);
            eventTalkDataVO.setNickname(users.getAvatar());
            eventTalkDataVO.setReceiver_id(receive_user);
            eventTalkDataVO.setTalk_type(talk_type);
            eventTalkDataVO.setUser_id(userId);

            ForwardVO forwardVO = new ForwardVO();
            ArrayList<ForwardListVO> forwardListVOS = new ArrayList<>();
            for (TalkRecords talkRecord : talkRecords) {
                ForwardListVO forwardListVO = new ForwardListVO();
                Users users1 = usersMapper.selectById(talkRecord.getUserId());
                forwardListVO.setNickname(users1.getNickName());
                forwardListVO.setText(MessageUtil.getMessageType(talkRecord.getMsgType(), talkRecord.getContent()));
                forwardListVOS.add(forwardListVO);
            }
            forwardVO.setList(forwardListVOS);
            forwardVO.setNum(forwardListVOS.size());

            eventTalkDataVO.setForward(forwardVO);
            eventTalkVO.setData(eventTalkDataVO);
            keepAlive.setContent(eventTalkVO);

            GetUserUtil.sendMessage(keepAlive, userId);
            if (talk_type == 1) {
                if (GetUserUtil.isOnLine(receive_user) == 1) {
                    GetUserUtil.sendMessage(keepAlive, receive_user);
                }
            } else {
                List<Integer> groupMember = groupMemberMapper.getGroupMember(receive_user);
                groupMember.remove(userId);
                for (Integer user_id : groupMember) {
                    if (GetUserUtil.isOnLine(user_id) == 1) {
                        GetUserUtil.sendMessage(keepAlive, user_id);
                    }
                }
            }
        }
    }

    /**
     * 获取会话消息详情
     *
     * @param record_id
     * @param userId
     * @return
     */
    @Override
    public Result recordsForward(Integer record_id, Integer userId) {
        QueryWrapper<TalkRecordsForward> talkRecordsForwardQueryWrapper = new QueryWrapper<>();
        talkRecordsForwardQueryWrapper.eq("record_id", record_id);
        TalkRecordsForward talkRecordsForward = forwardMapper.selectOne(talkRecordsForwardQueryWrapper);
        String[] records = talkRecordsForward.getRecordsId().split(",");
        List<String> stringList = Arrays.asList(records);
        RecordsDTO recordsDTO = new RecordsDTO();
        List<RecordsRowsVO> recordsRowsVOS = new ArrayList<>();

        for (String record : stringList) {
            TalkRecords talkRecords = getById(record);

            RecordsRowsVO recordsRowsVO = new RecordsRowsVO();

            recordsRowsVO.setId(talkRecords.getId());
            recordsRowsVO.setIs_mark(talkRecords.getIsMark());
            recordsRowsVO.setIs_read(talkRecords.getIsRead());
            recordsRowsVO.setIs_revoke(talkRecords.getIsRevoke());
            recordsRowsVO.setMsg_type(talkRecords.getMsgType());
            recordsRowsVO.setReceiver_id(talkRecords.getReceiverId());
            recordsRowsVO.setTalk_type(talkRecords.getTalkType());
            recordsRowsVO.setCreated_at(talkRecords.getUpdatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
            recordsRowsVO.setUser_id(talkRecords.getUserId());


            Users users = usersMapper.selectById(talkRecords.getUserId());

            recordsRowsVO.setAvatar(users.getAvatar());
            recordsRowsVO.setNickname(users.getNickName());
            switch (talkRecords.getMsgType()) {
                case 0:
                case 1:
                    recordsRowsVO.setContent(talkRecords.getContent());
                    break;
                case 2:
                    QueryWrapper<TalkRecordsFile> wrapper = new QueryWrapper<>();
                    wrapper.eq("record_id", talkRecords.getId());
                    TalkRecordsFile recordsType = talkRecordsFileMapper.selectOne(wrapper);

                    FileVO fileVO = new FileVO();
                    fileVO.setCreated_at(recordsType.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                    fileVO.setDrive(recordsType.getDrive());
                    fileVO.setId(recordsType.getId());
                    fileVO.setOriginal_name(recordsType.getOriginalName());
                    fileVO.setPath(recordsType.getPath());
                    fileVO.setRecord_id(recordsType.getRecordId());
                    fileVO.setSize(recordsType.getSize());
                    fileVO.setSource(recordsType.getSource());
                    fileVO.setSuffix(recordsType.getSuffix());
                    fileVO.setType(recordsType.getType());
                    fileVO.setUrl(recordsType.getUrl());
                    fileVO.setUser_id(recordsType.getUserId());

                    recordsRowsVO.setFile(fileVO);
                    break;
                /*case 3:
                    QueryWrapper<TalkRecordsForward> wrapperForward = new QueryWrapper<>();
                    wrapperForward.eq("record_id", talkRecords.getId());
                    TalkRecordsForward talkRecordsForward = forwardMapper.selectOne(wrapperForward);

                    ForwardVO forwardVO = new ForwardVO();
                    List<ForwardListVO> forwardListVOS = new ArrayList<>();
                    List<String> stringList = Arrays.asList(talkRecordsForward.getRecordsId().split(","));
                    for (String record : stringList) {
                        TalkRecords talkRecords2 = talkRecordsMapper.selectById(Integer.parseInt(record));
                        Users users1 = usersMapper.selectById(talkRecords2.getUserId());
                        ForwardListVO forwardListVO = new ForwardListVO(users1.getNickName(), MessageUtil.getMessageType(talkRecords2.getMsgType(), talkRecords2.getContent()));
                        forwardListVOS.add(forwardListVO);
                    }
                    forwardVO.setList(forwardListVOS);
                    forwardVO.setNum(forwardListVOS.size());

                    recordsRowsVO.setForward(forwardVO);
                    break;*/
                case 4:
                    QueryWrapper<TalkRecordsCode> wrapperCode = new QueryWrapper<>();
                    wrapperCode.eq("record_id", talkRecords.getId());
                    TalkRecordsCode talkRecordsCode = codeMapper.selectOne(wrapperCode);
                    CodeBlockVO codeBlockVO = new CodeBlockVO();
                    codeBlockVO.setCode(talkRecordsCode.getCode());
                    codeBlockVO.setRecord_id(talkRecords.getId());
                    codeBlockVO.setCreated_at(talkRecordsCode.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                    codeBlockVO.setId(talkRecordsCode.getId());
                    codeBlockVO.setLang(talkRecordsCode.getLang());
                    codeBlockVO.setUser_id(talkRecordsCode.getUserId());
                    recordsRowsVO.setCode_block(codeBlockVO);
                    break;
            }
            recordsRowsVOS.add(recordsRowsVO);
        }
        recordsDTO.setRows(recordsRowsVOS);
        return Result.success(recordsDTO);
    }

    /**
     * 获取聊天历史记录
     *
     * @param uid
     * @param talk_type
     * @param receiver_id
     * @param record_id
     * @param msg_type
     * @param limit
     * @return
     */
    @Override
    public Result recordsHistory(Integer uid, Integer talk_type, Integer receiver_id, Integer record_id, Integer msg_type, Integer limit) {
        List<TalkRecords> recordsList = talkRecordsMapper.recordsHistory(uid, talk_type, receiver_id, record_id, msg_type, limit);


        RecordsDTO recordsDTO = new RecordsDTO();
        recordsDTO.setLimit(limit);
        if (recordsList.size() > 0) {
            TalkRecords item = recordsList.get(recordsList.size() - 1);
            recordsDTO.setRecord_id(item.getId());

            List<RecordsRowsVO> recordsRowsVOS = new ArrayList<>();

            recordsRowsVOS = recordsList.stream().map(talkRecords -> {
                RecordsRowsVO recordsRowsVO = new RecordsRowsVO();
                recordsRowsVO.setId(talkRecords.getId());
                recordsRowsVO.setIs_mark(talkRecords.getIsMark());
                recordsRowsVO.setIs_read(talkRecords.getIsRead());
                recordsRowsVO.setIs_revoke(talkRecords.getIsRevoke());
                recordsRowsVO.setMsg_type(talkRecords.getMsgType());
                recordsRowsVO.setReceiver_id(talkRecords.getReceiverId());
                recordsRowsVO.setTalk_type(talkRecords.getTalkType());
                recordsRowsVO.setCreated_at(talkRecords.getUpdatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                recordsRowsVO.setUser_id(talkRecords.getUserId());

                Users users = usersMapper.selectById(talkRecords.getUserId());
                if (users != null) {
                    recordsRowsVO.setAvatar(users.getAvatar());
                    recordsRowsVO.setNickname(users.getNickName());
                }
                switch (talkRecords.getMsgType()) {
                    case 0:
                    case 1:
                        recordsRowsVO.setContent(talkRecords.getContent());
                        break;
                    case 2:
                        QueryWrapper<TalkRecordsFile> wrapper = new QueryWrapper<>();
                        wrapper.eq("record_id", talkRecords.getId());
                        TalkRecordsFile recordsType = talkRecordsFileMapper.selectOne(wrapper);

                        FileVO fileVO = new FileVO();
                        fileVO.setCreated_at(recordsType.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                        fileVO.setDrive(recordsType.getDrive());
                        fileVO.setId(recordsType.getId());
                        fileVO.setOriginal_name(recordsType.getOriginalName());
                        fileVO.setPath(recordsType.getPath());
                        fileVO.setRecord_id(recordsType.getRecordId());
                        fileVO.setSize(recordsType.getSize());
                        fileVO.setSource(recordsType.getSource());
                        fileVO.setSuffix(recordsType.getSuffix());
                        fileVO.setType(recordsType.getType());
                        fileVO.setUrl(recordsType.getUrl());
                        fileVO.setUser_id(recordsType.getUserId());

                        recordsRowsVO.setFile(fileVO);
                        break;
                    case 3:
                        QueryWrapper<TalkRecordsForward> wrapperForward = new QueryWrapper<>();
                        wrapperForward.eq("record_id", talkRecords.getId());
                        TalkRecordsForward talkRecordsForward = forwardMapper.selectOne(wrapperForward);

                        ForwardVO forwardVO = new ForwardVO();
                        List<ForwardListVO> forwardListVOS = new ArrayList<>();
                        List<String> stringList = Arrays.asList(talkRecordsForward.getRecordsId().split(","));
                        for (String record : stringList) {
                            TalkRecords talkRecords2 = talkRecordsMapper.selectById(Integer.parseInt(record));
                            Users users1 = usersMapper.selectById(talkRecords2.getUserId());
                            ForwardListVO forwardListVO = new ForwardListVO(users1.getNickName(), MessageUtil.getMessageType(talkRecords2.getMsgType(), talkRecords2.getContent()));
                            forwardListVOS.add(forwardListVO);
                        }
                        forwardVO.setList(forwardListVOS);
                        forwardVO.setNum(forwardListVOS.size());

                        recordsRowsVO.setForward(forwardVO);
                        break;
                    case 4:
                        QueryWrapper<TalkRecordsCode> wrapperCode = new QueryWrapper<>();
                        wrapperCode.eq("record_id", talkRecords.getId());
                        TalkRecordsCode talkRecordsCode = codeMapper.selectOne(wrapperCode);
                        CodeBlockVO codeBlockVO = new CodeBlockVO();
                        codeBlockVO.setCode(talkRecordsCode.getCode());
                        codeBlockVO.setRecord_id(talkRecords.getId());
                        codeBlockVO.setCreated_at(talkRecordsCode.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                        codeBlockVO.setId(talkRecordsCode.getId());
                        codeBlockVO.setLang(talkRecordsCode.getLang());
                        codeBlockVO.setUser_id(talkRecordsCode.getUserId());
                        recordsRowsVO.setCode_block(codeBlockVO);
                        break;
                    case 5://投票消息
                        QueryWrapper<TalkRecordsVote> talkRecordsVoteQueryWrapper = new QueryWrapper<>();
                        talkRecordsVoteQueryWrapper.eq("record_id", talkRecords.getId());
                        TalkRecordsVote talkRecordsVote = talkRecordsVoteMapper.selectOne(talkRecordsVoteQueryWrapper);

                        VoteVO voteVO = new VoteVO();

                        DetailVO detailVO = new DetailVO();
                        detailVO.setAnswer_mode(talkRecordsVote.getAnswerMode());
                        detailVO.setAnswer_num(talkRecordsVote.getAnswerNum());
                        detailVO.setAnswered_num(talkRecordsVote.getAnsweredNum());
                        detailVO.setId(talkRecordsVote.getId());
                        detailVO.setRecord_id(talkRecordsVote.getRecordId());
                        detailVO.setStatus(talkRecordsVote.getStatus());
                        detailVO.setTitle(talkRecordsVote.getTitle());

                        List<AnswerOptionVO> answerOptionVOS = new ArrayList<>();
                        String[] answerOptions = talkRecordsVote.getAnswerOption().split(",");
                        for (int i = 0; i < answerOptions.length; i++) {
                            AnswerOptionVO answerOptionVO = new AnswerOptionVO();

                            char key = (char) (65 + i);
                            answerOptionVO.setKey(String.valueOf(key));
                            answerOptionVO.setValue(answerOptions[i]);

                            answerOptionVOS.add(answerOptionVO);
                        }
                        detailVO.setAnswer_option(answerOptionVOS);
                        voteVO.setDetail(detailVO);

                        StatisticsVO statisticsVO = new StatisticsVO();
                        statisticsVO.setCount(talkRecordsVote.getAnsweredNum());
                        Map<String, Long> options = new HashMap<>();
                        for (int i = 0; i < answerOptions.length; i++) {
                            char key = (char) (65 + i);
                            QueryWrapper<TalkRecordsVoteAnswer> talkRecordsVoteAnswerQueryWrapper = new QueryWrapper<>();
                            talkRecordsVoteAnswerQueryWrapper.eq("vote_id", talkRecordsVote.getId()).eq("answer_option", String.valueOf(key));
                            Long count = talkRecordsVoteAnswerMapper.selectCount(talkRecordsVoteAnswerQueryWrapper);
                            options.put(String.valueOf(key), count);
                        }
                        statisticsVO.setOptions(options);
                        voteVO.setStatistics(statisticsVO);

                        List<Integer> voteUsers = new ArrayList<>();
                        QueryWrapper<TalkRecordsVoteAnswer> talkRecordsVoteAnswerQueryWrapper = new QueryWrapper<>();
                        talkRecordsVoteAnswerQueryWrapper.eq("vote_id", talkRecordsVote.getId());
                        List<TalkRecordsVoteAnswer> talkRecordsVoteAnswers = talkRecordsVoteAnswerMapper.selectList(talkRecordsVoteAnswerQueryWrapper);
                        voteUsers = talkRecordsVoteAnswers.stream().map(TalkRecordsVoteAnswer::getUserId).collect(Collectors.toList());
                        voteVO.setVote_users(voteUsers);
                        recordsRowsVO.setVote(voteVO);
                        break;
                    case 6:
                        QueryWrapper<GroupNotice> groupNoticeQueryWrapper = new QueryWrapper<>();
                        groupNoticeQueryWrapper.eq("record_id", talkRecords.getId());
                        GroupNotice groupNotice = groupNoticeMapper.selectOne(groupNoticeQueryWrapper);
                        NoticeVO noticeVO = new NoticeVO();
                        noticeVO.setConfirm_users(groupNotice.getConfirmUsers());
                        noticeVO.setContent(groupNotice.getContent());
                        noticeVO.setCreated_at(groupNotice.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                        noticeVO.setCreator_id(groupNotice.getCreatorId());
                        noticeVO.setGroup_id(groupNotice.getGroupId());
                        noticeVO.setId(groupNotice.getId());
                        noticeVO.setIs_confirm(groupNotice.getIsConfirm());
                        noticeVO.setIs_delete(groupNotice.getIsDelete());
                        noticeVO.setIs_top(groupNotice.getIsTop());
                        noticeVO.setTitle(groupNotice.getTitle());
                        noticeVO.setUpdated_at(groupNotice.getUpdatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));

                        Users creatorUser = usersMapper.selectById(groupNotice.getCreatorId());
                        noticeVO.setAvatar(creatorUser.getAvatar());
                        noticeVO.setNickname(creatorUser.getNickName());
                        recordsRowsVO.setNotice(noticeVO);
                        break;
                    case 8:
                        QueryWrapper<TalkRecordsLogin> talkRecordsLoginQueryWrapper = new QueryWrapper<>();
                        talkRecordsLoginQueryWrapper.eq("record_id", talkRecords.getId());
                        TalkRecordsLogin talkRecordsLogin = talkRecordsLoginMapper.selectOne(talkRecordsLoginQueryWrapper);

                        LoginVO loginVO = new LoginVO();
                        loginVO.setAddress(talkRecordsLogin.getAddress());
                        loginVO.setAgent(talkRecordsLogin.getAgent());
                        loginVO.setCreated_at(talkRecordsLogin.getCreatedAt().format(DateTimeFormatter.ofPattern(Common.LOCALDATETIME_FORMATER)));
                        loginVO.setIp(talkRecordsLogin.getIp());
                        loginVO.setPlatform(talkRecordsLogin.getPlatform());
                        loginVO.setReason(talkRecordsLogin.getReason());

                        recordsRowsVO.setLogin(loginVO);
                        break;
                    case 9:
                        QueryWrapper<TalkRecordsInvite> talkRecordsInviteQueryWrapper = new QueryWrapper<>();
                        talkRecordsInviteQueryWrapper.eq("record_id", talkRecords.getId());
                        TalkRecordsInvite talkRecordsInvite = talkRecordsInviteMapper.selectOne(talkRecordsInviteQueryWrapper);

                        InviteVO inviteVO = new InviteVO();
                        inviteVO.setType(1);//入群通知

                        UserVO operate_user = new UserVO();
                        Users user = usersMapper.selectById(talkRecordsInvite.getOperateUserId());
                        operate_user.setId(user.getId());
                        operate_user.setNickname(user.getNickName());
                        inviteVO.setOperate_user(operate_user);

                        String[] userIds = talkRecordsInvite.getUserIds().split(",");
                        List<String> userIdsList = Arrays.asList(userIds);
                        List<UserVO> userVOS = new ArrayList<>();
                        userVOS = userIdsList.stream().map(id -> {
                            Users users1 = usersMapper.selectById(id);
                            UserVO userVO = new UserVO();
                            userVO.setId(users1.getId());
                            userVO.setNickname(users1.getNickName());
                            return userVO;
                        }).collect(Collectors.toList());
                        inviteVO.setUsers(userVOS);
                        recordsRowsVO.setInvite(inviteVO);
                }

                return recordsRowsVO;
            }).collect(Collectors.toList());
            recordsDTO.setRows(recordsRowsVOS);
        }

        return Result.success(recordsDTO);
    }
}
